# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_realname=configparser
pkgbase=mingw-w64-python2-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-python2-${_realname}"
pkgver=4.0.2
pkgrel=1
pkgdesc="This library brings the updated configparser from Python 3.5 to Python 2.6-3.5 (mingw-w64)"
arch=('any')
url="https://github.com/jaraco/configparser/"
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-python2" 
         "${MINGW_PACKAGE_PREFIX}-python2-backports")
makedepends=("${MINGW_PACKAGE_PREFIX}-python2-setuptools" "${MINGW_PACKAGE_PREFIX}-python2-setuptools-scm")
source=("https://pypi.io/packages/source/c/configparser/${_realname}-${pkgver}.tar.gz" 
        license)
sha256sums=('c7d282687a5308319bf3d2e7706e575c635b0a470342641c93bea0ea3b5331df'
            '8c692bafaeb99a822a74d7180c578b14ea3b958095c3d75536ba4932420dad16')

prepare() {
  sed -i -e "s|#![ ]*/usr/bin/env python$|#!/usr/bin/env python2|" \
    $(find "${srcdir}"/${_realname}-$pkgver -name '*.py')
  rm -rf python2-build-${CARCH} | true
  cp -r "${_realname}-$pkgver" "python2-build-${CARCH}"
  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver
}

build() {
  msg "Python 2 build for ${CARCH}" 
  cd "${srcdir}"/python2-build-${CARCH}

  ${MINGW_PREFIX}/bin/python2 setup.py build
}


package() {
  cd "${srcdir}"/python2-build-${CARCH}

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python2 setup.py install --root="$pkgdir" --prefix=${MINGW_PREFIX} --optimize=1 --skip-build 

  rm "$pkgdir${MINGW_PREFIX}"/lib/python2.7/site-packages/backports/__init__.py{,c,o}
  install -D "${srcdir}/"license "$pkgdir${MINGW_PREFIX}/share/licenses/python2-${_realname}/LICENSE"
}
